import axios from '@/libs/axios1'
let jsonHeaders = { 'content-type': 'application/json;charset=UTF-8' }
//获取接入组列表-新
export const getaccessgrouplist = params => {
	return new Promise(resolve => {
		axios({
			url: `/process/accessGroups`,
			method: 'get',
			params: params,
			headers: jsonHeaders
		}).then(async res => {
			if (res && res.data && res.data.items) {
				// 将接口返回的数据结构转化为页面所需的数据结构
				let promises = res.data.items.map(async item => {
					if (item.partyName === undefined) { // partyName存在未设置的情况，没有设置时，与名称保持一致
						await getpartylist({
							id: Number(item.partyId)
						}).then(({ code, attribute = {} }) => {
							if (code === 1) {
								item.partyName = (attribute.dataList || [{}])[0].name
							}
						})
					}
					return item
				})
				await Promise.all(promises).then(list => {
					res.data.items = list
				})
			}
			resolve(res)
		})
	})
}
export const getaccessgrouplistdis = (params,sceneId) => {
	return axios({
			url: `/compete/contest/getDistRangeSceneTeams/${sceneId}`,
			method: 'get',
			params: params,
			headers: jsonHeaders
		})
}

//查询工程阵营列表
export const getpartylist = params=>{
	return axios({
		url: `/topo-edit/parties`,
		method: 'get',
		params: params,
		headers: jsonHeaders
	})
}

//创建工程接入组-新
export const addaccessgroup = (params)=>{
	return axios({
		url: `/process/accessGroups`,
		method: 'post',
		data: params,
		headers: jsonHeaders
	})
}

//查询工程接入组信息-新
export const getaccessgroupinfo = groupId => {
  return axios({
    url: `/process/accessGroups/${groupId}`,
    method: 'get',
    headers: jsonHeaders
  })
}


//修改工程接入组-新
export const modifyaccessgroup = (path,params)=>{
	return axios({
		url: `/process/accessGroups/${path.groupId}`,
		method: 'put',
		data: params,
		headers: jsonHeaders
	})
}

//删除工程接入组-新
export const delaccessgroup = (groupId)=>{
	return axios({
		url: `/process/accessGroups/${groupId}`,
		method: 'delete',
		headers: jsonHeaders
	})
}

//获取工程接入组成员 
export const getaccessgroupmember = (groupId)=>{
	return axios({
		url: `/process/accessGroups/${groupId}/assignUsers`,
		method: 'get',
		headers: jsonHeaders
	})
}

//获取当前登录用户所在课件用户组列表
export const getexpergrouplist = params=>{
	return axios({
		url: `/identity/experimenterGroups`,
		method: 'get',
		params:params,
		headers: jsonHeaders
	})
}
//获取课件用户组下的用户
export const getexpergroupusers = params=>{
	return axios({
		url: `/identity/experimenterGroups/${params}/users`,
		method: 'get',
		headers: jsonHeaders
	})
}

//添加工程接入组成员
export const addaccessgroupuser = (groupId,userIds)=>{
	return axios({
		url: `/process/accessGroups/${groupId}/assignUsers`,
		method: 'put',
		data: userIds,
		headers: jsonHeaders
	})
}

//添加工程接入组成员--众测新接口
export const addaccessgroupuserNew = (projectId,testId,accessGroupId,userIds)=>{
	return axios({
		url: `/compete/contest/addUsers?projectId=${projectId}&testId=${testId}&accessGroupId=${accessGroupId}`,
		method: 'post',
		data: userIds,
		headers: jsonHeaders
	})
}

//移除工程接入组成员--众测新接口
export const removeaccessgroupuserNew = (projectId,testId,accessGroupId,userIds)=>{
	return axios({
		url: `/compete/contest/removeUsers?projectId=${projectId}&testId=${testId}&accessGroupId=${accessGroupId}&teamId=${accessGroupId}`,
		method: 'post',
		data: userIds,
		headers: jsonHeaders
	})
}

//踢出工程接入组成员
export const removeaccessgroupuser = (path)=>{
	return axios({
		url: `/topo-edit/projects/${path.projectId}/project_access_members/${path.userId}`,
		method: 'delete',
		headers: jsonHeaders
	})
}

//获取场景接入组下用户(含接入机器列表)params含testId,pageIndex,pageSize)
export const getuserinstance = params=>{ 
	return axios({
		url: `/process/assign/userView`,
		method: 'get',
		params:params,
		headers: jsonHeaders
	})
}

// 获取场景接入组下用户(含接入机器列表)，排除了内部服务用户
export const getUserInstanceExclude = params=>{ 
	return axios({
		url: `/compete/topoTargetAllot/pkgAssignUserView`,
		method: 'get',
		params:params,
		headers: jsonHeaders
	})
}

//创建或修改用户虚拟机关系
export const setuservmrelation = params=>{
	return axios({
		url: `/process/assign/devicesToUser`,
		method: 'put',
		data:params,
		headers: jsonHeaders
	})
}

//删除用户虚拟机关系
export const removeuservmrelation = (params)=>{
	return axios({
		url: `/userjoin/instanceUserRelatione/deleteInstanceUserRelatione`,
		method: 'delete',
		params:params,
		headers: jsonHeaders
	})
}

//获取邀请码
export const getinvitecode = (path)=>{
	return axios({
		url: `/topo-edit/projects/${path.projectId}/project_access_groups/${path.groupId}/invites`,
		method: 'post',
		headers: jsonHeaders
	})
}

//获取提交申请人员
export const getapplyuser = params=>{
	return axios({
		url: `/topo-edit/project_access_members`,
		method: 'get',
		params:params,
		headers: jsonHeaders
	})
}

//是否同意加入工程接入组
export const joinaccessgroup = (path,params) =>{
	return axios({
		url: `/topo-edit/projects/${path.projectId}/project_access_members/${path.userId}`,
		method: 'put',
		params:params,
		headers: jsonHeaders
	})
}

//查询工程下所有的子网
export const getprojsubnet = params=>{
	return axios({
//		url: `/deploy/project/subnets`,
    url: `/topo-edit/deployed/projects/${params.projectId}/subnets`,
		method: 'get',
		params:params,
		headers: jsonHeaders
	})
}

// 获取元数据信息
export const getprojsubnetNodes = (projectId,nodeId)=>{
	return axios({
    url: `/topo-edit/topo/projects/${projectId}/nodes/${nodeId}`,
		method: 'get',
		// params:params,
		headers: jsonHeaders
	})
}

//分配竞赛资源
export const assignresource = params =>{
	return axios({
		url: `/nsrep-allocation/resource/binding`,
		method: 'post',
		data:params,
		headers: jsonHeaders
	})
}

//删除所有配置
export const  clearconfig = params =>{
	return axios({
		url: `/nsrep-allocation/resource/delete/${params.projectId}/${params.sceneId}`,
		method: 'delete',
		headers: jsonHeaders
	})
}

//查询子网与用户组关系
export const getprojsubnetRelation = params=>{
	return axios({
		url: `/nsrep-allocation/resource/queryRelation/${params.projectId}/${params.sceneId}`,
		method: 'get',
		headers: jsonHeaders
	})
}

//删除用户场景关系
export const  delsceneusers = (refId,userIds) =>{
	return axios({
		url: `/compete/sceneUser/deleteByUserIds/${refId}`,
		method: 'delete',
		data:userIds,
		headers: jsonHeaders
	})
}
//获取交换机列表
export const  changelist = params =>{
  return axios({
    url: `/sdn/switchs/list`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}
//获取端口列表
export const  postlist = params =>{
  return axios({
    url: `/sdn/switchs/port/${params}/unlinked/list`,
    method: 'get',
    headers: jsonHeaders
  })
}
//保存虚实结合接口
export const  savevirtualreal = params =>{
  return axios({
    url: `/nsrep-allocation/interconnection/allot`,
    method: 'post',
    data:params,
    headers: jsonHeaders
  })
}
//查询所有虚实结合列表
export const  getvirtulreallist = (prjid,sencenid,params) =>{
  return axios({
    url: `/nsrep-allocation/interconnection/${prjid}/${sencenid}`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}
//删除虚实结合记录
export const  delvirulreal = (id) =>{
  return axios({
    url: `/nsrep-allocation/interconnection/delUserPort/${id}`,
    method: 'delete',
    headers: jsonHeaders
  })
}
//修改虚实结合（单个信息）
export const  modifyvirtualreal = params =>{
  return axios({
    url: `/nsrep-allocation/interconnection/updateUserPort`,
    method: 'put',
    data:params,
    headers: jsonHeaders
  })
}
//获取团队连接子网信息
export const  getteaminfo = params =>{
  return axios({
    url: `/nsrep-allocation/interconnection/${params.projectId}/${params.sceneId}/${params.groupId}`,
    method: 'get',
    headers: jsonHeaders
  })
}

//将设备分配给多个用户
export const userToDevices = params =>{
  return axios({
    url: `/process/assign/userToDevices`,
    method: 'put',
    data:params,
    headers: jsonHeaders
  })
}

//获取用户虚拟机关系
export const getUserDevices = (testId,userIds) =>{
  return axios({
    url: `/process/assign/uSearch?testId=${testId}`,
    method: 'post',
    data:userIds,
    headers: jsonHeaders
  })
}

//查询场景虚拟机分配记录
export const  getAssignRecord = params =>{
  return axios({
    url: `/process/assign/records`,
    method: 'get',
    params:params,
    headers: jsonHeaders
  })
}
//查询场景虚拟机分配记录
export const getAllRanges = () => {
  return axios({
    url: `/range-manager/unsafe/range`,
    method: 'get',
    headers: jsonHeaders
  })
}

//录屏转码
export const transcodingBySessionId = (sessionId) => {
  return axios({
    url: `/access/storage/transcodingBySessionId`,
    method: 'post',
    params: { sessionId },
    headers: jsonHeaders
  })
}

//查询转码状态
export const queryTranscodingStatus = (params) => {
  return axios({
    url: `/access/tasks`,
    method: 'get',
    params: params,
    headers: jsonHeaders
  })
}